# load data
datos <- read.table("salida.out", header=T) # host ms hr nombre km fibra
graf <- "ms-vs-fibra.png"

hosts = datos$host
mss = datos$ms
kms = datos$km
fibras = datos$fibra

len = length(hosts)

print(datos)

# plot
png(filename=graf, width=1024, height=768, bg="white")

# increase y-axis margin. (bottom, left, top, right)
par(mar=c(10,5,5,2))

# Calculate range from 0 to max value
g_range <- range(0, mss, fibras)

# Graph using y axis that ranges from 0 to max 
# Turn off axes and 
# annotations (axis labels) so we can specify them ourself
plot(mss, type="b", col="blue", ylim=g_range, 
   axes=FALSE, ann=FALSE)

# Make y axis with horizontal labels that display ticks at 
# every 100 marks. 100*0:g_range[2] is equivalent to c(0,100,200,...,1000).
axis(2, las=1, 100*0:g_range[2])

# Make x axis tick marks without labels
axis(1, lab=F, at=1:len)

# Plot x axis labels at default tick marks with labels at 
# 45 degree angle
text(1:len, par("usr")[3] - 20, srt=45, adj=1,
    labels=hosts,
    xpd=T, cex=0.8,)

# Create box around plot
box()

# Graph
lines(fibras, type="b", pch=22, lty=2, col="red")
title(main="Ping")
title(xlab="Hosts")
title(ylab="Time (ms)")

# legend 
legend(1, 300, c("ping","fibra"), cex=0.8, bty="b",
   col=c("blue","red"), pch=21:22, lty=1:2);
   
dev.off()
